home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0191_A Drives handling unit.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-11-29  |  18.6 KB  |  780 lines

  1. unit Disques;
  2.  
  3. interface
  4.  
  5. uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  6.      FileCtrl,LZExpand,ShellAPI;
  7.  
  8. // Constants
  9. const
  10.      (* drive type *)
  11.      _drive_not_exist = 255;
  12.      _drive_floppy    = 1;
  13.      _drive_hard      = 2;
  14.      _drive_network   = 3;
  15.      _drive_CDRom     = 4;
  16.      _drive_RAM       = 5;
  17.      (* directory option *)
  18.      _directory_recurrent      = 1;
  19.      _directory_not_recurrent  = 0;
  20.      _directory_force          = 1;
  21.      _directory_not_force      = 0;
  22.      _directory_clear_file     = 1;
  23.      _directory_not_clear_file = 0;
  24.      (* file error *)
  25.      _File_Unable_To_Delete     = 10;
  26.      _File_Copied_Ok            = 0;
  27.      _File_Already_Exists       = 1;
  28.      _File_Bad_Source           = 2;
  29.      _File_Bad_Destination      = 3;
  30.      _File_Bad_Source_Read      = 4;
  31.      _File_Bad_Destination_Read = 5;
  32.      (* copy switch *)
  33.      _File_copy_Overwrite       = 1;
  34.  
  35. // Drives
  36. function _Drive_Type (_Drive : char) : byte;
  37. function _Drive_As_Disk (_Drive: Char): Boolean;
  38. function _Drive_Size (_Drive : char) : longint;
  39. function _Drive_Free (_Drive : char) : longint;
  40.  
  41. // Directories
  42. function _Directory_Exist (_Dir : string) : boolean;
  43. function _Directory_Create (_Dir : string) : boolean;
  44. function _Directory_Delete (_Dir  : string;ClearFile : byte) : boolean;
  45. function _Directory_Delete_Tree (_Dir : string; ClearFile : byte) : boolean;
  46. function _Directory_Rename (_Dir,_NewDir : string) : boolean;
  47.  
  48. // Files
  49. function _File_Exist (_File : string) : boolean;
  50. function _File_Delete (_File : string) : boolean;
  51. function _File_Recycle (_File : string) : boolean;
  52. function _File_Rename (_File,_NewFile : string;_Delete : byte) : boolean;
  53. function _File_Copy_UnCompress (FromFile,ToFile : string;Switch : byte) : byte;
  54. function _File_Copy(source,dest: String): Boolean;
  55. function _File_Move (_Source,_Destination : string) : boolean;
  56. function _File_Get_Attrib (_File : string) : byte;
  57. function _File_Set_Attrib (_File : string;_Attrib : byte) : boolean;
  58. function _File_Get_Date (_File : string) : string;
  59. function _File_Set_Date (_File,_Date : string) : boolean;
  60. function _File_Get_Size (_File : string) : longint;
  61. function _File_Start (AppName,AppParams,AppDir : string) : integer;
  62.  
  63. // Miscellaneous
  64. function _Get_WindowsDir : string;
  65. function _Get_SystemDir : string;
  66. function _Get_TempDir : string;
  67. function _Get_Apps_Dir (ExeName : PChar) : string;
  68. function _Get_Apps_Drive (ExeName : PChar) : string;
  69. function _Get_WindowsVer : real;
  70. function _Get_WindowsBuild : real;
  71. function _Get_WindowsPlatform : string;
  72. function _Get_WindowsExtra : string;
  73.  
  74. implementation
  75.  
  76.  
  77. (**********)
  78. (* drives *)
  79. (**********)
  80.  
  81.  
  82. (* type of drive *)
  83. function _Drive_Type (_Drive : char) : byte;
  84. var i: integer;
  85.     c : array [0..255] of char;
  86. begin
  87.  _Drive := upcase (_Drive);
  88.  if not (_Drive in ['A'..'Z']) then
  89.   Result := _drive_not_exist
  90.  else
  91.  begin
  92.   strPCopy (c,_Drive + ':\');
  93.   i := GetDriveType (c);
  94.   case i of
  95.    DRIVE_REMOVABLE: result := _drive_floppy;
  96.    DRIVE_FIXED    : result := _drive_hard;
  97.    DRIVE_REMOTE   : result := _drive_network;
  98.    DRIVE_CDROM    : result := _drive_CDRom;
  99.    DRIVE_RAMDISK  : result := _drive_RAM;
  100.   else
  101.    result := _drive_not_exist;
  102.   end;
  103.  end;
  104. end;
  105.  
  106. (* test is a disk is in drive *)
  107. function _Drive_As_Disk (_Drive: Char): Boolean;
  108. var ErrorMode: Word;
  109. begin
  110.  _Drive := UpCase(_Drive);
  111.  if not (_Drive in ['A'..'Z']) then
  112.  raise
  113.   EConvertError.Create ('Not a valid drive letter');
  114.  ErrorMode := SetErrorMode (SEM_FailCriticalErrors);
  115.  try
  116.   Application.ProcessMessages;
  117.   Result := (DiskSize ( Ord(_Drive) - Ord ('A') + 1) <> -1);
  118.  finally
  119.   SetErrorMode(ErrorMode);
  120.   Application.ProcessMessages;
  121.  end;
  122. end;
  123.  
  124. (* size of drive *)
  125. function _Drive_Size (_Drive : char) : longint;
  126. var ErrorMode : word;
  127. begin
  128.  _Drive := upcase (_Drive);
  129.  if not (_Drive in ['A'..'Z']) then
  130.  raise
  131.   EConvertError.Create ('Not a valid drive letter');
  132.  ErrorMode := SetErrorMode (SEM_FailCriticalErrors);
  133.  try
  134.   Application.ProcessMessages;
  135.   Result := DiskSize ( Ord(_Drive) - Ord ('A') + 1);
  136.  finally
  137.   SetErrorMode (ErrorMode);
  138.  end;
  139. end;
  140.  
  141. (* free space in drive *)
  142. function _Drive_Free (_Drive : char) : longint;
  143. var ErrorMode : word;
  144. begin
  145.  _Drive := upcase (_Drive);
  146.  if not (_Drive in ['A'..'Z']) then
  147.  raise
  148.   EConvertError.Create ('Not a valid drive letter');
  149.  ErrorMode := SetErrorMode (SEM_FailCriticalErrors);
  150.  try
  151.   Application.ProcessMessages;
  152.   Result := DiskFree ( Ord(_Drive) - Ord ('A') + 1);
  153.  finally
  154.   SetErrorMode (ErrorMode);
  155.  end;
  156. end;
  157.  
  158.  
  159. (***************)
  160. (* directories *)
  161. (***************)
  162.  
  163. (* directory exists or not *)
  164. function _Directory_Exist (_Dir : string) : boolean;
  165. VAR  OldMode : Word;
  166.      OldDir  : String;
  167. BEGIN
  168.  Result := True;
  169.  GetDir(0, OldDir);
  170.  OldMode := SetErrorMode(SEM_FAILCRITICALERRORS);
  171.  try
  172.   try
  173.    ChDir(_Dir);
  174.  except
  175.    ON EInOutError DO
  176.     Result := False;
  177.  end;
  178.  finally
  179.    ChDir(OldDir);
  180.    SetErrorMode(OldMode);
  181.  end;
  182. END;
  183.  
  184. (* create a directory enven if parent does not exists *)
  185. function _Directory_Create (_Dir : string) : boolean;
  186. begin
  187.  ForceDirectories(_Dir);
  188.  Result := _Directory_Exist (_Dir);
  189. end;
  190.  
  191. (* delete a directory *)
  192. function _Directory_Delete (_Dir : string;ClearFile : byte) : boolean;
  193. begin
  194.  if _Directory_Exist (_Dir) then
  195.   Result := RemoveDir (_Dir)
  196.  else
  197.   Result := false;
  198. end;
  199.  
  200. (* delete a tree *)
  201. function _directory_delete_tree (_Dir : string; ClearFile : byte) : boolean;
  202. var SearchRec : TSearchRec;
  203.     Erc : Word;
  204. begin
  205.  if _Directory_Exist (_Dir) then
  206.  begin
  207.   Try
  208.    ChDir (_Dir);
  209.    FindFirst('*.*',faAnyFile,SearchRec);
  210.    Erc := 0;
  211.    while Erc = 0 do
  212.    begin
  213.     if ((SearchRec.Name <> '.' ) and
  214.        (SearchRec.Name <> '..')) then
  215.     begin
  216.      if (SearchRec.Attr and faDirectory > 0) then
  217.       _Directory_Delete_Tree (SearchRec.Name,ClearFile)
  218.      else
  219.       if ClearFile = 1 then
  220.        _File_Delete (SearchRec.Name);
  221.     end;
  222.     Erc := FindNext (SearchRec);
  223.    end;
  224.    FindClose (SearchRec);
  225.    Application.ProcessMessages;
  226.   finally
  227.    if Length(_Dir) > 3 then
  228.     ChDir ('..' );
  229.    Result := RemoveDir (_Dir);
  230.   end;
  231.  end
  232.  else
  233.  (* not exists *)
  234.   Result := false;
  235. end;
  236.  
  237. (* Renamme a directory *)
  238. function _Directory_Rename (_Dir,_NewDir : string) : boolean;
  239. var SearchRec : TSearchRec;
  240.     Erc : Word;
  241.     f : file;
  242.     o : string;
  243. begin
  244.  if _Directory_Exist (_Dir) then
  245.  begin
  246.   Try
  247.    (* just name of directory *)
  248.    o := _dir;
  249.    Delete (o,1,2); (* remove drive and : *)
  250.    if o [1] = '\' then delete (o,1,1); (* remove \ at begin *)
  251.    if o [length (o)] = '\' then
  252.     o := copy (o,1,length (o)-1); (* delete \ at end *)
  253.    ChDir (_Dir);
  254.    ChDir ('..');
  255.    FindFirst('*.*',faAnyFile,SearchRec);
  256.    Erc := 0;
  257.    while Erc = 0 do
  258.    begin
  259.     if ((SearchRec.Name <> '.' ) and
  260.        (SearchRec.Name <> '..')) then
  261.     begin
  262.      if (SearchRec.Attr and faDirectory > 0) then
  263.      begin
  264.       if SearchRec.Name = o then
  265.       begin
  266.        assignfile (f,SearchRec.Name);
  267.        {$I-};
  268.         rename (F,_NewDir);
  269.        {I+};
  270.        result := (ioresult = 0);
  271.       end;
  272.      end;
  273.     end;
  274.     Erc := FindNext (SearchRec);
  275.    end;
  276.    Application.ProcessMessages;
  277.   finally
  278.    if Length(_Dir) > 3 then
  279.     ChDir ('..' );
  280.   end;
  281.   FindClose (SearchRec);
  282.  end
  283.  else
  284.  (* not exists *)
  285.   Result := false;
  286. end;
  287.  
  288.  
  289. (*********)
  290. (* files *)
  291. (*********)
  292.  
  293. (* file exists or not *)
  294. function _File_Exist (_File : string) : boolean;
  295. begin
  296.  _File_Exist := FileExists(_File);
  297. end;
  298.  
  299. (* delete a file remove -r if needed *)
  300. function _File_Delete (_File : string) : boolean;
  301. begin
  302.  if FileExists (_File) then
  303.  begin
  304.   _File_Set_Attrib (_File,0);
  305.   Result := DeleteFile (_File);
  306.  end
  307.  else
  308.   Result := false;
  309. end;
  310.  
  311. (* send a file to recycle *)
  312. function _File_Recycle(_File : TFilename): boolean;
  313. var Struct: TSHFileOpStruct;
  314.     pFromc: array[0..255] of char;
  315.     Resul  : integer;
  316. begin
  317.  if not FileExists(_File) then
  318.  begin
  319.   _File_Recycle := False;
  320.   exit;
  321.  end
  322.  else
  323.  begin
  324.   fillchar(pfromc,sizeof(pfromc),0);
  325.   StrPcopy(pfromc,expandfilename(_File)+#0#0);
  326.   Struct.wnd := 0;
  327.   Struct.wFunc := FO_DELETE;
  328.   Struct.pFrom := pFromC;
  329.   Struct.pTo   := nil;
  330.   Struct.fFlags:= FOF_ALLOWUNDO or FOF_NOCONFIRMATION    ;
  331.   Struct.fAnyOperationsAborted := false;
  332.   Struct.hNameMappings := nil;
  333.   Resul := ShFileOperation(Struct);
  334.   _File_Recycle := (Resul = 0);
  335.  end;
  336. end;
  337.  
  338. (* renamme a file, delete if needed *)
  339. function _File_Rename (_File,_NewFile : string;_Delete : byte) : boolean;
  340. var f : file;
  341. begin
  342.  if FileExists (_File) then
  343.  begin
  344.   if FileExists (_NewFile) then
  345.   begin
  346.    if _Delete = 0 then
  347.     Result := false
  348.    else
  349.     _File_Delete (_NewFile);
  350.   end;
  351.   assignfile (f,_File);
  352.   {$I-};
  353.    Rename (f,_NewFile);
  354.   {$I+};
  355.   Result := (ioresult = 0);
  356.  end
  357.  else
  358.   Result := false;
  359. end;
  360.  
  361. (* copy a file *)
  362. function _File_Copy_UnCompress (FromFile,ToFile : string;Switch : byte) : byte;
  363. var Tmp : integer;
  364.     FromF, ToF: file;
  365.     NumRead, NumWritten: Word;
  366.     iHandle : Integer;
  367.     iNewHandle : Integer;
  368.     iReturn : Integer;
  369.     iLongReturn : LongInt;
  370.     pFrom : Array[0..256] of Char;
  371.     pTo : Array[0..256] of Char;
  372. begin
  373.  Tmp := 0;
  374.  If (FileExists (ToFile)) and (Switch = 0) then
  375.   Tmp := 1
  376.  else
  377.  begin
  378.   StrPCopy( pFrom, FromFile );
  379.   iReturn := GetExpandedName( pFrom, pTo );
  380.   if iReturn = -1 then
  381.    Tmp := 2
  382.   else
  383.   begin
  384.    if iReturn = -2 then
  385.     Tmp := 3
  386.    else
  387.    begin
  388.     if ( StrEnd( pTo ) - pTo ) > 0 then
  389.     begin
  390.      ToFile := ExtractFilePath( ToFile ) +
  391.                ExtractFileName( strPas( pTo ) );
  392.      iHandle := FileOpen( FromFile, fmShareDenyWrite );
  393.      LZInit (iHandle);
  394.      if iHandle < 1 then
  395.       Tmp := 2
  396.      else
  397.      begin
  398.       iNewHandle := FileCreate( ToFile );
  399.       if iNewHandle < 1 then
  400.        Tmp := 3
  401.       else
  402.       begin
  403.        iLongReturn := LZCopy( iHandle , iNewHandle );
  404.        if iLongReturn = LZERROR_UNKNOWNALG then
  405.         Tmp := 5
  406.        else
  407.        begin
  408.         FileClose( iHandle );
  409.         FileClose( iNewHandle );
  410.         LZClose (iHandle);
  411.        end;
  412.       end;
  413.      end;
  414.     end
  415.     else
  416.      Tmp := 3;
  417.    end
  418.   end;
  419.  end;
  420.  _File_Copy_UnCompress := Tmp;
  421. end;
  422.  
  423. (* just copy a file *)
  424. function _File_Copy(source,dest: String): Boolean;
  425. var
  426.   fSrc,fDst,len: Integer;
  427.   size: Longint;
  428.   buffer: packed array [0..2047] of Byte;
  429. begin
  430.   if pos ('\\',source) <> 0 then delete (source,pos ('\\',source),1);
  431.   if pos ('\\',dest) <> 0 then delete (dest,pos ('\\',dest),1);
  432.   Result := False;
  433.   if source <> dest then
  434.   begin
  435.    fSrc := FileOpen(source,fmOpenRead);
  436.    if fSrc >= 0 then
  437.    begin
  438.     size := FileSeek(fSrc,0,2);
  439.     FileSeek(fSrc,0,0);
  440.     fDst := FileCreate(dest);
  441.     if fDst >= 0 then begin
  442.      while size > 0 do
  443.      begin
  444.        len := FileRead(fSrc,buffer,sizeof(buffer));
  445.        FileWrite(fDst,buffer,len);
  446.        size := size - len;
  447.      end;
  448.      FileSetDate(fDst,FileGetDate(fSrc));
  449.      FileClose(fDst);
  450.      FileSetAttr(dest,FileGetAttr(source));
  451.      Result := True;
  452.     end;
  453.     FileClose(fSrc);
  454.    end;
  455.   end;
  456. end;
  457.  
  458. (* move a file *)
  459. function _File_Move (_Source,_Destination : string) : boolean;
  460. var Tmp : boolean;
  461. begin
  462.  tmp := _File_Copy (_Source,_Destination);
  463.  if Tmp = true then
  464.   if _File_Delete (_Source) = true then
  465.    Tmp := true
  466.   else
  467.    Tmp := false;
  468.  Result := Tmp;
  469. end;
  470.  
  471. (* Get file attributes *)
  472. function _File_Get_Attrib (_File : string) : byte;
  473. var Tmp : byte;
  474.     Att : integer;
  475. begin
  476.  if FileExists (_File) then
  477.  begin
  478.   Att := FileGetAttr (_File);
  479.   if Att <> -1 then
  480.   begin
  481.    Tmp := 0;
  482.    if (Att AND faReadOnly) = faReadOnly then Tmp := Tmp + 1;
  483.    if (Att AND faHidden) = faHidden then Tmp := Tmp + 2;
  484.    if (Att AND faSysFile) = faSysFile then Tmp := Tmp + 4;
  485.    if (Att AND faArchive) = faArchive then Tmp := Tmp + 8;
  486.    Result := Tmp;
  487.   end
  488.   else
  489.    Result := 255;
  490.  end
  491.  else
  492.   Result := 255;
  493. end;
  494.  
  495. (* Set file attributes *)
  496. function _File_Set_Attrib (_File : string;_Attrib : byte) : boolean;
  497. var Tmp : integer;
  498. begin
  499.  if FileExists (_File) then
  500.  begin
  501.   Tmp := 0;
  502.   if _Attrib and 1 = 1 then Tmp := tmp OR faReadOnly;
  503.   if _Attrib and 2 = 2 then Tmp := tmp OR faHidden;
  504.   if _Attrib and 4 = 4 then Tmp := tmp OR faSysFile;
  505.   if _Attrib and 8 = 8 then Tmp := tmp OR faArchive;
  506.   Result := FileSetAttr (_File,Tmp) = 0;
  507.  end
  508.  else
  509.   Result := false
  510. end;
  511.  
  512. (* Get datestamp of file *)
  513. function _File_Get_Date (_File : string) : string;
  514. var f   : file;
  515.     Hdl : integer;
  516.     Tmp : string;
  517.     Dte : integer;
  518.     Dat : TDateTime;
  519. begin
  520.  Tmp := '';
  521.  Hdl := FileOpen(_File, fmOpenRead or fmShareDenyNone);
  522.  if Hdl > 0 then
  523.  begin
  524.   Dte := FileGetDate (Hdl);
  525.   FileClose (Hdl);
  526.   Dat := FileDateToDateTime (Dte);
  527.   Tmp := DateToStr (Dat);
  528.   while pos ('/',Tmp) <> 0 do delete (Tmp,pos ('/',Tmp),1);
  529.   if length (tmp) > 6 then delete (Tmp,5,2);
  530.  end;
  531.  Result := Tmp;
  532. end;
  533.  
  534. (* Set datestamp of file *)
  535. function _File_Set_Date (_File,_Date : string) : boolean;
  536. var f   : file;
  537.     Hdl : integer;
  538.     Dte : integer;
  539.     Dat : TDateTime;
  540.     Att : integer;
  541. begin
  542.  Att := _File_Get_Attrib (_File);
  543.  if (Att AND 1) <> 1 then Att := 0
  544.                      else _File_Set_Attrib (_File,0);
  545.  Hdl := FileOpen(_File, fmOpenReadWrite or fmShareDenyNone);
  546.  if Hdl > 0 then
  547.  begin
  548.   if length (_Date) < 8 then Insert ('19',_Date,5);
  549.   if pos ('/',_Date) = 0 then
  550.    _Date := copy (_Date,1,2) + '/' +
  551.             copy (_Date,3,2) + '/' +
  552.             copy (_Date,5,4);
  553.   Dat := StrToDateTime (_Date);
  554.   Dte := DateTimeToFileDate (Dat);
  555.   Result := FileSetDate (Hdl,Dte) = 0;
  556.   FileClose (Hdl);
  557.   if Att <> 0 then
  558.     _File_Set_Attrib (_File,Att);
  559.  end
  560.  else
  561.  begin
  562.   if Att <> 0 then
  563.     _File_Set_Attrib (_File,Att);
  564.   Result := False;
  565.  end;
  566. end;
  567.  
  568. (* return size of a file *)
  569. function _File_Get_Size (_File : string) : longint;
  570. var f: file of Byte;
  571.     a : integer;
  572. begin
  573.  if FileExists (_File) then
  574.  begin
  575.   a := _File_Get_Attrib (_File);
  576.   if (a AND 1) = 1 then
  577.    _File_Set_Attrib (_File,0)
  578.   else
  579.    a := 0;
  580.   AssignFile(f,_File);
  581.   {$I-};
  582.    Reset(f);
  583.   {$I+};
  584.   if ioresult = 0 then
  585.   begin
  586.    Result := FileSize(f);
  587.    CloseFile(f);
  588.    if a <> 0 then
  589.     _File_Set_Attrib (_File,a);
  590.   end
  591.   else
  592.   begin
  593.    if a <> 0 then
  594.     _File_Set_Attrib (_File,a);
  595.    Result := -1;
  596.   end;
  597.  end
  598.  else
  599.   Result := -1;
  600. end;
  601.  
  602. (* lancement d'une application *)
  603. function _File_Start (AppName,AppParams,AppDir : string) : integer;
  604. var Tmp : Integer;
  605.     zFileName : array [0 .. 79] of char;
  606.     zParams   : array [0 .. 79] of char;
  607.     zDir      : array [0 .. 79] of Char;
  608. begin
  609.  Tmp := 0;
  610.  StrPCopy (zFileName,AppName);
  611.  StrPCopy (zParams,AppParams);
  612.  StrPCopy (zDir,AppDir);
  613.  Tmp := ShellExecute (0,Nil,zFileName,zParams,zDir,1);
  614.  _File_Start := Tmp;
  615. end;
  616.  
  617.  
  618.  
  619. (*****************)
  620. (* miscellaneous *)
  621. (*****************)
  622.  
  623. (* return Windows directory *)
  624. function _Get_WindowsDir : string;
  625. var Tmp : array [0 .. 255] of char;
  626.     Ret : string;
  627. begin
  628.  if GetWindowsDirectory (Tmp,255) <> 0 then
  629.  begin
  630.   Ret := StrPas (Tmp);
  631.   if Ret [length (Ret)] = '\' then
  632.    Ret := copy (Ret,1,length (Ret) - 1);
  633.   Result := Ret;
  634.  end
  635.  else
  636.   Result := '';
  637. end;
  638.  
  639. (* return Windows system directory *)
  640. function _Get_SystemDir : string;
  641. var Tmp : array [0 .. 255] of char;
  642.     Ret : string;
  643. begin
  644.  if GetSystemDirectory (Tmp,255) <> 0 then
  645.  begin
  646.   Ret := StrPas (Tmp);
  647.   if Ret [length (Ret)] = '\' then
  648.    Ret := copy (Ret,1,length (Ret) - 1);
  649.   Result := Ret;
  650.  end
  651.  else
  652.   Result := '';
  653. end;
  654.  
  655. (* return Windows Temp directory *)
  656. function _Get_TempDir : string;
  657. var Tmp : array [0 .. 255] of char;
  658.     Ret : string;
  659. begin
  660.  if GetTempPath (255,Tmp) <> 0 then
  661.  begin
  662.   Ret := StrPas (Tmp);
  663.   if Ret [length (Ret)] = '\' then
  664.    Ret := copy (Ret,1,length (Ret) - 1);
  665.   Result := Ret;
  666.  end
  667.  else
  668.   Result := '';
  669. end;
  670.  
  671. (* return application directory *)
  672. function _Get_Apps_Dir (ExeName : PChar) : string;
  673. var Hdl : THandle;
  674.     Nam : PChar;
  675.     Fil : array [0..255] of char;
  676.     Siz : integer;
  677.     Ret : integer;
  678.     Pas : string;
  679.     Pat : string [79];
  680. begin
  681.  Pat := '';
  682.  Hdl := GetModuleHandle (ExeName);
  683.  Ret := GetModuleFileName (Hdl,Fil,Siz);
  684.  Pas := StrPas (Fil);
  685.  Pat := ExtractFilePath (Pas);
  686.  Delete (Pat,1,2);
  687.  if Pat [length (Pat)] = '\' then
  688.   Pat := copy (Pat,1,length (Pat) - 1);
  689.  Result := Pat;
  690. end;
  691.  
  692. (* return dirve of current application *)
  693. function _Get_Apps_Drive (ExeName : PChar) : string;
  694. var Hdl : THandle;
  695.     Nam : PChar;
  696.     Fil : array [0..255] of char;
  697.     Siz : integer;
  698.     Ret : integer;
  699.     Pas : string;
  700.     Drv : string [02];
  701. begin
  702.  Drv := '';
  703.  Hdl := GetModuleHandle (ExeName);
  704.  Ret := GetModuleFileName (Hdl,Fil,Siz);
  705.  Pas := StrPas (Fil);
  706.  Drv := ExtractFilePath (Pas);
  707.  _Get_Apps_Drive := Drv;
  708. end;
  709.  
  710. (* return windows version as a real *)
  711. function _Get_WindowsVer : real;
  712. var tempo   : string;
  713.     Temp    : real;
  714.     err     : integer;
  715.     struct  : TOSVersionInfo;
  716. begin
  717.  struct.dwOSVersionInfoSize := sizeof (Struct);
  718.  struct.dwMajorVersion := 0;
  719.  struct.dwMinorVersion := 0;
  720.  GetVersionEx (Struct);
  721.  Tempo  := inttostr (Struct.dwMajorVersion) + '.' + inttostr (Struct.dwMinorVersion);
  722.  val (tempo,temp,err);
  723.  Result := Temp;
  724. end;
  725.  
  726. (* return type of platform *)
  727. function _Get_WindowsPlatform : string;
  728. var tempo   : string;
  729.     Temp    : string;
  730.     err     : integer;
  731.     struct  : TOSVersionInfo;
  732. begin
  733.  struct.dwOSVersionInfoSize := sizeof (Struct);
  734.  struct.dwPlatformId := 0;
  735.  GetVersionEx (Struct);
  736.  case struct.dwPlatformid of
  737.   ver_platform_win32s : temp := 'Win32S';
  738.   ver_platform_win32_windows : temp := 'Win32';
  739.   ver_platform_win32_nt : temp := 'WinNT';
  740.  end;
  741.  Result := Temp;
  742. end;
  743.  
  744. (* get extra information *)
  745. function _Get_WindowsExtra : string;
  746. var tempo   : string;
  747.     Temp    : string;
  748.     err     : integer;
  749.     struct  : TOSVersionInfo;
  750. begin
  751.  struct.dwOSVersionInfoSize := sizeof (Struct);
  752.  struct.dwMajorVersion := 0;
  753.  struct.dwMinorVersion := 0;
  754.  struct.dwBuildNumber := 0;
  755.  struct.dwPlatformId := 0;
  756.  GetVersionEx (Struct);
  757.  Temp := '';
  758.  Temp := strPas (Struct.szCSDVersion);
  759.  Result := Temp;
  760. end;
  761.  
  762. (* return windows build as a real *)
  763. function _Get_WindowsBuild : real;
  764. var tempo   : string;
  765.     Temp    : real;
  766.     err     : integer;
  767.     struct  : TOSVersionInfo;
  768. begin
  769.  struct.dwOSVersionInfoSize := sizeof (Struct);
  770.  struct.dwBuildNumber := 0;
  771.  GetVersionEx (Struct);
  772.  tempo := inttostr (struct.dwBuildNumber AND $0000FFFF);
  773.  val (tempo,temp,err);
  774.  Result := Temp;
  775. end;
  776.  
  777. begin
  778. end.
  779.  
  780.